package com.hontech.bread.ui.parts

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.Button
import android.widget.FrameLayout
import com.hontech.bread.R
import com.hontech.bread.ui.BaseActivity
import com.hontech.bread.ui.view.LabelSpinner
import com.hontech.bread.utils.setLocale

class LangParts(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) {

    init {
        val view = LayoutInflater.from(context).inflate(R.layout.parts_lang, this)
        val sp = view.findViewById<LabelSpinner>(R.id.id_lang_sp)
        val btn = view.findViewById<Button>(R.id.id_lang_btn_set)

        btn.setOnClickListener {
            when (sp.selectIndex()) {
                0 -> setLocale("zh", "CN")
                1 -> setLocale("en", "US")
            }
            // restartAppWithDelay()
            BaseActivity.INSTANCE.restart()
        }
    }
}